package com.ruoyi.web.controller.system;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.system.domain.res.projectLog.ProjectLogDay_res;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ProjectLog;
import com.ruoyi.system.service.IProjectLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 竞标项目日志Controller
 *
 * @author ruoyi
 * @date 2024-09-04
 */
@RestController
@RequestMapping("/system/projectLog")
public class ProjectLogController extends BaseController {
    @Resource
    private IProjectLogService projectLogService;

    /**
     * 查询竞标项目日志列表
     */
    //@PreAuthorize("@ss.hasPermi('system:projectLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectLog projectLog) {
        startPage();
        LoginUser loginUser = getLoginUser();
        if (!loginUser.getDeptId().equals(1000001L)) {
            projectLog.getParams().put("deptId", loginUser.getDeptId());
        }
        List<ProjectLog> list = projectLogService.selectProjectLogList(projectLog);
        return getDataTable(list);
    }

    /**
     * 查询中标记录
     */
    @GetMapping("/selectProjectLogDay")
    @Anonymous
    public TableDataInfo selectProjectLogDay(ProjectLog projectLog) {
        startPage();
        List<ProjectLogDay_res> list = projectLogService.selectProjectLogDay(projectLog);
        return getDataTable(list);
    }

    @GetMapping("/list_anonymous")
    @Anonymous
    public TableDataInfo list_anonymous(ProjectLog projectLog) {
        if (Convert.toInt(ServletUtils.getParameter("pageNum")) != -1
                && Convert.toInt(ServletUtils.getParameter("pageSize")) != -1) {
            startPage();
        }
        projectLog.setStatus(2);
        List<ProjectLog> list = projectLogService.selectProjectLogList(projectLog);
        return getDataTable(list);
    }

    /**
     * 导出竞标项目日志列表
     */
    //@PreAuthorize("@ss.hasPermi('system:projectLog:export')")
    @Log(title = "竞标项目日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectLog projectLog) {
        List<ProjectLog> list = projectLogService.selectProjectLogList(projectLog);
        ExcelUtil<ProjectLog> util = new ExcelUtil<ProjectLog>(ProjectLog.class);
        util.exportExcel(response, list, "竞标项目日志数据");
    }

    /**
     * 获取竞标项目日志详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:projectLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(projectLogService.selectProjectLogById(id));
    }

    /**
     * 新增竞标项目日志
     */
    //@PreAuthorize("@ss.hasPermi('system:projectLog:add')")
    @Log(title = "竞标项目日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectLog projectLog) {
        LoginUser loginUser = getLoginUser();
        projectLog.setDeptId(loginUser.getDeptId());
        projectLog.setUserId(loginUser.getUserId());
        return toAjax(projectLogService.insertProjectLog(projectLog));
    }

    /**
     * 修改竞标项目日志
     */
    //@PreAuthorize("@ss.hasPermi('system:projectLog:edit')")
    @Log(title = "竞标项目日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectLog projectLog) {
        return toAjax(projectLogService.updateProjectLog(projectLog));
    }

    /**
     * 删除竞标项目日志
     */
    //@PreAuthorize("@ss.hasPermi('system:projectLog:remove')")
    @Log(title = "竞标项目日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(projectLogService.deleteProjectLogByIds(ids));
    }
}
